package com.zhaojun.cloud.service.api.hystrix;

import com.zhaojun.cloud.common.pojo.User;
import com.zhaojun.cloud.service.api.UserService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * wwj
 * 2019/2/18  13:49
 * 用户服务降级
 */
@Component
public class HystrixFallBackUserService implements FallbackFactory<UserService> {

    private Logger logger = LoggerFactory.getLogger(HystrixFallBackUserService.class);

    @Override
    public UserService create(Throwable throwable) {
        logger.error("【HystrixFallBackUserService】：接口异常:"+throwable,throwable);
        return id -> {
            User user =  new User();
            user.setId(-1l);
            return user;
        };
    }
}
